/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelGestionConsultorios.java
 *
 * Created on 26/09/2011, 06:31:55 PM
 */

package views;

import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author JARR
 */
public class PanelGestionConsultorios extends javax.swing.JPanel {

    /** Creates new form PanelGestionConsultorios */
    public PanelGestionConsultorios() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel5 = new javax.swing.JLabel();
        CTID = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        RBCrear = new javax.swing.JRadioButton();
        BDoble = new javax.swing.JButton();
        BEliminar = new javax.swing.JButton();
        RBModificar = new javax.swing.JRadioButton();
        jLabel6 = new javax.swing.JLabel();
        CTNuevoID = new javax.swing.JTextField();
        panelNombre = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        CTEspecializacion = new javax.swing.JTextField();
        Estado = new javax.swing.JLabel();
        CBEStado = new javax.swing.JComboBox();

        jLabel5.setFont(new java.awt.Font("Dialog", 1, 14));
        jLabel5.setText("oprima ENTER");

        CTID.setFont(new java.awt.Font("Dialog", 0, 14));
        CTID.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                CTIDFocusGained(evt);
            }
        });
        CTID.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                CTIDKeyPressed(evt);
            }
            public void keyReleased(java.awt.event.KeyEvent evt) {
                CTIDCTKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                CTIDCTKeyTyped(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel1.setText("Digite la ID del consultorio, escoja la transacción que desea hacer y");

        jLabel2.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel2.setText("ID");

        RBCrear.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        RBCrear.setText("Crear Consultorio");
        RBCrear.setOpaque(false);
        RBCrear.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                RBCrearRBMouseReleased(evt);
            }
        });
        RBCrear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RBCrearActionPerformed(evt);
            }
        });

        BDoble.setBackground(new java.awt.Color(0, 0, 51));
        BDoble.setFont(new java.awt.Font("Dialog", 1, 14));
        BDoble.setForeground(new java.awt.Color(204, 204, 204));
        BDoble.setText("jButton1");
        BDoble.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BDobleActionPerformed(evt);
            }
        });

        BEliminar.setBackground(new java.awt.Color(0, 0, 51));
        BEliminar.setFont(new java.awt.Font("Dialog", 1, 14));
        BEliminar.setForeground(new java.awt.Color(204, 204, 204));
        BEliminar.setText("Eliminar Paciente");
        BEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BEliminarActionPerformed(evt);
            }
        });

        RBModificar.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        RBModificar.setText("Modificar Consultorio");
        RBModificar.setOpaque(false);
        RBModificar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                RBModificarRBMouseReleased(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel6.setText("Nuevo ID:");

        CTNuevoID.setFont(new java.awt.Font("Dialog", 0, 14));
        CTNuevoID.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                CTNuevoIDCTKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                CTNuevoIDCTKeyTyped(evt);
            }
        });

        panelNombre.setBackground(new java.awt.Color(250, 250, 255));

        jLabel4.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        jLabel4.setText("Especializacion");

        CTEspecializacion.setFont(new java.awt.Font("Dialog", 0, 14));

        Estado.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
        Estado.setText("Estado");

        CBEStado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout panelNombreLayout = new javax.swing.GroupLayout(panelNombre);
        panelNombre.setLayout(panelNombreLayout);
        panelNombreLayout.setHorizontalGroup(
            panelNombreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelNombreLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelNombreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(Estado))
                .addGap(8, 8, 8)
                .addGroup(panelNombreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(CBEStado, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(CTEspecializacion, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        panelNombreLayout.setVerticalGroup(
            panelNombreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelNombreLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelNombreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Estado)
                    .addComponent(CBEStado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(panelNombreLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CTEspecializacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 600, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(44, 44, 44)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(CTID, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(RBCrear)
                            .addComponent(RBModificar)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(100, 100, 100)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(CTNuevoID, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(panelNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 442, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 557, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(157, 157, 157)
                        .addComponent(BEliminar)
                        .addGap(52, 52, 52)
                        .addComponent(BDoble)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 409, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addGap(29, 29, 29)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(CTID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(RBModificar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(RBCrear)))
                .addGap(44, 44, 44)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(CTNuevoID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(panelNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(66, 66, 66)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(BDoble)
                    .addComponent(BEliminar))
                .addContainerGap(15, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void CTIDFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_CTIDFocusGained
       // String cadena = CTDNI.getText();
        boolean bandera = RBCrear.isSelected();
       // iniciarPanel();
        RBCrear.setSelected(bandera);
       // CTDNI.setText(cadena);
      //  CTDNI.selectAll();
}//GEN-LAST:event_CTIDFocusGained

    private void CTIDKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CTIDKeyPressed
        if (evt.getKeyCode() == 10) {
         //   transaccion();
        }
}//GEN-LAST:event_CTIDKeyPressed

    private void CTIDCTKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CTIDCTKeyReleased
        JTextField obj = (JTextField) evt.getSource();
        while (!obj.getText().isEmpty() && (obj.getText().charAt(0) < '0' || (int) obj.getText().charAt(0) > '9')) {
            obj.setText(obj.getText().substring(1));
        }
}//GEN-LAST:event_CTIDCTKeyReleased

    private void CTIDCTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CTIDCTKeyTyped
        JTextField obj = (JTextField) evt.getSource();
        if (obj.getSelectionStart() == 0 && (evt.getKeyChar() < '1' || evt.getKeyChar() > '9')) {
            evt.consume();
        } else if ((evt.getKeyChar() < '0' || evt.getKeyChar() > '9')) {
            evt.consume();
        } else if (obj.getText().length() >= 12 && obj.getSelectionEnd() - obj.getSelectionStart() <= 0) {
            evt.consume();
        }
}//GEN-LAST:event_CTIDCTKeyTyped

    private void RBCrearRBMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RBCrearRBMouseReleased
    //    CTDNI.requestFocus();
}//GEN-LAST:event_RBCrearRBMouseReleased

    private void RBCrearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RBCrearActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_RBCrearActionPerformed

    private void BDobleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BDobleActionPerformed
        /*if (CTNombre.getText().isEmpty() || CTApellidos.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Ni el nombre ni el apellido del usuario pueden estar en blanco.", "Campos de texto", JOptionPane.WARNING_MESSAGE);
            if (CTNombre.getText().isEmpty()) {
                CTNombre.requestFocus();
            } else {
                CTApellidos.requestFocus();
            }
        } else {
            if (BDoble.getText().equals("Modificar Usuario")) {
                if (CTNuevoDNI.getText().length() < 7) {
                    JOptionPane.showMessageDialog(this, "El DNI del usuario debe ser de mínimo 7 caracteres.", "Campos de texto", JOptionPane.WARNING_MESSAGE);
                    CTNuevoDNI.requestFocus();
                } else {
                    JOptionPane.showMessageDialog(this, Constructores.mu.actualizarUsuario(usuarioSeleccionado, CTNuevoDNI.getText(), CTNombre.getText(), CTApellidos.getText()));
                    CTDNI.requestFocus();
                    FrameMenuPrincipal.setUsuarioEnSesion(Constructores.udao.consultarUsuario(CTNuevoDNI.getText()));
                }

            } else if (BDoble.getText().equals("Agregar Usuario")) {
                Paciente u = new Paciente(CTDNI.getText(), CTNombre.getText(), CTApellidos.getText());
                JOptionPane.showMessageDialog(this, Constructores.mu.agregarUsuario(u));
                CTDNI.requestFocusInWindow();
            }
        }*/
}//GEN-LAST:event_BDobleActionPerformed

    private void BEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BEliminarActionPerformed
        if (JOptionPane.showConfirmDialog(this, "¿Está seguro de querer eliminar el usuario actual?", "Eliminación de Usuario", JOptionPane.YES_NO_OPTION) == 0) {
         //   JOptionPane.showMessageDialog(this, Constructores.mu.eliminarUsuario(CTDNI.getText()));
           // usuarioSeleccionado = null;
         //   CTDNI.requestFocusInWindow();
        }
}//GEN-LAST:event_BEliminarActionPerformed

    private void RBModificarRBMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RBModificarRBMouseReleased
       // CTDNI.requestFocus();
}//GEN-LAST:event_RBModificarRBMouseReleased

    private void CTNuevoIDCTKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CTNuevoIDCTKeyReleased
        JTextField obj = (JTextField) evt.getSource();
        while (!obj.getText().isEmpty() && (obj.getText().charAt(0) < '0' || (int) obj.getText().charAt(0) > '9')) {
            obj.setText(obj.getText().substring(1));
        }
}//GEN-LAST:event_CTNuevoIDCTKeyReleased

    private void CTNuevoIDCTKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CTNuevoIDCTKeyTyped
        JTextField obj = (JTextField) evt.getSource();
        if (obj.getSelectionStart() == 0 && (evt.getKeyChar() < '1' || evt.getKeyChar() > '9')) {
            evt.consume();
        } else if ((evt.getKeyChar() < '0' || evt.getKeyChar() > '9')) {
            evt.consume();
        } else if (obj.getText().length() >= 12 && obj.getSelectionEnd() - obj.getSelectionStart() <= 0) {
            evt.consume();
        }
}//GEN-LAST:event_CTNuevoIDCTKeyTyped


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BDoble;
    private javax.swing.JButton BEliminar;
    private javax.swing.JComboBox CBEStado;
    private javax.swing.JTextField CTEspecializacion;
    private javax.swing.JTextField CTID;
    private javax.swing.JTextField CTNuevoID;
    private javax.swing.JLabel Estado;
    private javax.swing.JRadioButton RBCrear;
    private javax.swing.JRadioButton RBModificar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel panelNombre;
    // End of variables declaration//GEN-END:variables

}
